#!/bin/sh

LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")

/usr/bin/wget --spider --quiet --tries=3 --timeout=3 www.gstatic.com/generate_204

if [ "$?" -eq "0" ]; then
	echo "[$LOGTIME] ShadowsocksR No Problem."
else
	/usr/bin/wget --spider --quiet --tries=3 --timeout=3 www.baidu.com
	if [ "$?" -eq "0" ]; then
		echo "[$LOGTIME] Problem decteted, restarting ShadowsocksR..."
		/etc/init.d/ssrpro restart
	else
		echo "[$LOGTIME] Network Problem. Do nothing."
	fi
fi
